package com.wyd;

import com.wyd.proxy.MyProxyServlet;
import com.wyd.proxy.MyProxyServlet2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
public class ApplicationProxy {

	@Bean
	public ServletRegistrationBean exampleServletBean() {
		ServletRegistrationBean bean = new ServletRegistrationBean(
				new MyProxyServlet(), "/proxy/*");
		bean.setLoadOnStartup(1);

		Map<String, String> map = new HashMap<>();
		map.put("log", "true");
		map.put("targetUri", "http://127.0.0.1:8081");
		bean.setInitParameters(map);

		return bean;
	}

	@Bean
	public ServletRegistrationBean exampleServletBean2() {
		ServletRegistrationBean bean = new ServletRegistrationBean(
				new MyProxyServlet2(), "/proxy2/*");
		bean.setLoadOnStartup(1);

		Map<String, String> map = new HashMap<>();
		map.put("log", "true");
		map.put("targetUri", "");
		bean.setInitParameters(map);

		return bean;
	}

	public static void main(String[] args) {
		SpringApplication.run(ApplicationProxy.class, args);
	}

}
